package com.monster.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.monster.pojo.Permission;
import com.monster.pojo.User;
import com.monster.vo.RoleVO;
import com.monster.vo.UserVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface UserDetailMapper extends BaseMapper<User> {

    @Select("select id,username,password from t_user where username = #{username}")
    UserVO findUserByName(@Param("username") String username);

    @Select("select distinct tr.id,tr.KEYWORD " +
            "from t_role tr , t_user_role tur " +
            "where  tr.id = tur.ROLE_ID  " +
            "and USER_ID = #{id}")
    List<RoleVO> findRolesByUserId(@Param("id") Integer id);

    @Select("select distinct tp.KEYWORD " +
            "from t_permission tp , t_role_permission trp  " +
            "where tp.id = trp.PERMISSION_ID " +
            "and ROLE_ID = #{id}")
    List<Permission> findPermissionByRoleId(@Param("id") Integer id);
}
